package concurrent_250224;

public class interval2 {

    public static void main(String[] args) throws InterruptedException {
        Run1 run1 = new Run1();
        new Thread(run1,"thread1").start();
        new Thread(run1,"thread2").start();

        Thread.sleep(1000*5);
    }

}

class Run1 implements Runnable{

    private Integer count = 0;

    @Override
    public void run() {
        try {
            increment();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized void increment() throws InterruptedException {
        while (count < 100) {
            notify();
            count++;
            System.out.println(Thread.currentThread().getName()+":"+count);
            wait();
        }

    }
}
